package chu.dejian.entity;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

/**
 * Created by Administrator on 2015/12/16 0016.
 */
public class MeasureMessageEntity implements Parcelable{
    public int messageId = -1;
    public String message;
    public int systolic;
    public int diastolic;
    public int pulse;
    public String timeStr;
    public boolean isNew = true;
    public boolean isRead = false;

    public String attendee;
    public int attendee_uid;
    public int level;
    public int measurement;
    public double latitude, longitude;
    public String pulsestate;
    public String note;


    public MeasureMessageEntity(){}


    protected MeasureMessageEntity(Parcel in) {
        messageId = in.readInt();
        message = in.readString();
        systolic = in.readInt();
        diastolic = in.readInt();
        pulse = in.readInt();
        timeStr = in.readString();
        isNew = in.readByte() != 0;
        isRead = in.readByte() != 0;
        attendee = in.readString();
        attendee_uid = in.readInt();
        level = in.readInt();
        measurement = in.readInt();
        latitude = in.readDouble();
        longitude = in.readDouble();
        pulsestate = in.readString();
        note = in.readString();
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeInt(messageId);
        dest.writeString(message);
        dest.writeInt(systolic);
        dest.writeInt(diastolic);
        dest.writeInt(pulse);
        dest.writeString(timeStr);
        dest.writeByte((byte) (isNew ? 1 : 0));
        dest.writeByte((byte) (isRead ? 1 : 0));
        dest.writeString(attendee);
        dest.writeInt(attendee_uid);
        dest.writeInt(level);
        dest.writeInt(measurement);
        dest.writeDouble(latitude);
        dest.writeDouble(longitude);
        dest.writeString(pulsestate);
        dest.writeString(note);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<MeasureMessageEntity> CREATOR = new Creator<MeasureMessageEntity>() {
        @Override
        public MeasureMessageEntity createFromParcel(Parcel in) {
            return new MeasureMessageEntity(in);
        }

        @Override
        public MeasureMessageEntity[] newArray(int size) {
            return new MeasureMessageEntity[size];
        }
    };

    public String getForMatchStr(){
        StringBuilder sb = new StringBuilder();
        if(!TextUtils.isEmpty(attendee)) sb.append(attendee).append(" ");
        if(!TextUtils.isEmpty(message)) sb.append(message).append(" ");
        if(!TextUtils.isEmpty(timeStr)) sb.append(timeStr).append(" ");
        sb.append(systolic).append(" ").append(diastolic).append(" ").append(pulse);
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if(o == null) return false;
        if(this == o) return true;
        if(o instanceof MeasureMessageEntity){
            MeasureMessageEntity mme = (MeasureMessageEntity) o;
            return mme.messageId == messageId && mme.systolic == systolic && mme.diastolic == diastolic && mme.pulse == pulse;
        }
        return false;
    }

    @Override
    public int hashCode() {
        return messageId + systolic + diastolic + pulse;
    }

}
